
class Storage {
  key = "";

  constructor(key) {
    this.key = key;
  }

  get () {
    try {
      const str = localStorage.getItem(this.key);
      const value  = JSON.parse(str);
      return value?.data || null;
    } catch (error) {
      console.log(`storage.${this.key}.error`, error);
      return null;
    }
  }

  set (data) {
    const value = {
      expires: null,
      updateat: new Date().getTime(),
      data,
    };
    localStorage.setItem(this.key, JSON.stringify(value));
  }

  destroy () {
    localStorage.removeItem(this.key);
  }
}

export default Storage;
